# 
# (C) Copyright 2019 - ShenYongchen.
#
#
###############################################################################
# 
# source path
set(src_path "bzip2-1.0.6")

# library name
set(dll_name "bz2")
set(sll_name lib${dll_name})

# BZ2_PUBLIC_HDRS
set(BZ2_PUBLIC_HDRS ${BZ2_PUBLIC_HDRS}
  ${src_path}/bzlib.h
)

# source code
set(lib_srcs ${lib_srcs}
  ${src_path}/blocksort.c
  ${src_path}/huffman.c
  ${src_path}/crctable.c
  ${src_path}/randtable.c
  ${src_path}/compress.c
  ${src_path}/decompress.c
  ${src_path}/bzlib.c
)

# ststic library
add_library(${sll_name} STATIC ${lib_srcs})

# dynamic library
add_library(${dll_name} SHARED ${lib_srcs} "${src_path}/bzlib.def")


#[[ app_SRCS
  bzip2.c
  bzip2recover.c
  dlltest.c
  mk251.c
  spewG.c
  unzcrash.c
#-------------------------------------------------------------------------]]
# 
# bzip2
# 
add_executable(bzip2 ${src_path}/bzip2.c)
target_link_libraries(bzip2 ${sll_name})

# 
# bzip2recover
# 
add_executable(bzip2recover ${src_path}/bzip2recover.c)


# 
# install
# 
set_install_prefix("d:/sfxTools/bzip2")

install(TARGETS ${sll_name} ${dll_name} bzip2 bzip2recover
  RUNTIME DESTINATION "bin"
  LIBRARY DESTINATION "lib"
  ARCHIVE DESTINATION "lib" # 静态库安装路径
  # EXPORT MyLibTargets 
)

install(FILES ${BZ2_PUBLIC_HDRS} DESTINATION "${SFX_INSTALL_INC_DIR}")

# install(TARGETS MyLib
#         EXPORT MyLibTargets 
#         LIBRARY DESTINATION lib  # 动态库安装路径
#         ARCHIVE DESTINATION lib  # 静态库安装路径
#         RUNTIME DESTINATION bin  # 可执行文件安装路径
#         PUBLIC_HEADER DESTINATION include  # 头文件安装路径
#         )


# if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
#     install(TARGETS zlib zlibstatic
#         RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
#         ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
#         LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
# endif()
# if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
#     install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}")
# endif()
# if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
#     install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3")
# endif()
# if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
#     install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
# endif()
